package com.cn.wanxi.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.IUserService;
import com.cn.wanxi.service.impl.UserServiceImpl;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/user/del")
public class UserDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//        得到页面数据
        String id = req.getParameter("id");
//        封装对象
        UserModel userModel = new UserModel();
        userModel.setId(Tool.stringToInt(id));
//        调用服务逻辑层
        IUserService iUserService = new UserServiceImpl();
//        得到返回数据
        String result = iUserService.del(userModel);
//        /**
//         * 举例
//         */
//        final int[] agea = {18};
////        值传递和引用传递
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                int age = 19;
//                agea[0] = age;
//            }
//        });
//        返回页面数据
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        resp.getWriter().println(jsonObject);
    }
}
